package practise.alogrithm.hundredInterviewQuestions;

/**
 * Created by angela on 6/8/2014.
 */
public class MinNumberInAReverseArray {
    public static Integer findMinNumberFromReverseArray(int[] array){
        int startIndex=0, endIndex=array.length-1;
        while(startIndex<endIndex-1){
            int midIndex = (startIndex+endIndex)/2;
            if(array[endIndex]<array[midIndex]){//note, we must use end in compare, as we try to get the latest one, else we can not get one when array already sorted
                startIndex=midIndex;
            }
            else{
                endIndex = midIndex;
            }
        }

        return Math.min(array[startIndex],array[endIndex]);
    }

    public static void main(String[] args){
        System.out.print("Result:"+findMinNumberFromReverseArray(new int[]{4,5,6,7,1,2,3}));
    }
}
